{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Simple Black-box Adversarial Attacks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Paper link: https://arxiv.org/abs/1905.07121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bat.attacks import SimBA\n",
    "from bat.apis.deepapi import VGG16Cifar10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.set_printoptions(suppress=True)\n",
    "\n",
    "from PIL import Image"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Load image and make predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Image ranging from [0.0, 1.0]\n",
    "x = np.asarray(Image.open(\"dog.jpg\").resize((32, 32))) / 255.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib.pyplot import imshow\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x24bac36d788>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAd0UlEQVR4nO2de6ydZ5Xen/V9+3Luto9vGDuJQ3CGBJgkYCLowAxlOqMMRQqoFQpqaf6IJqPRUJVqqipipJJKbcVUBcQfFZVpogkt5VICQ9TSdtJ0JIRaMh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uMIir4yNCPbvA9g33FlsALgHwGOjdsLMJs1s+uXHAH4bwDPxrHXlMQwKdwIbWMDz5eAa8iGMYE3MzDCoYficu3/mMtNI14T5Meo1Wbcir6PaYXzVbuP7MdjpfB7AH22QD2/AQAn4EYAfj9IPAF/G4ONgF4O/ve7DoGfeEwB+BuB/ApjdID/+A4CnARzCINh2jcCPd2PwEf0QgKeG/94/6jUJ/BjpmgD4VQyKuB7C4I3ln112zf4FgMMA/jOA5pUcV9+gEyITct+gEyIbFOxCZIKCXYhMULALkQkKdiEyQcEuRCYo2IXIBAW7EJnw/wA8XOFh3NssMwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "imshow(np.asarray(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize the DeepAPI Model\n",
    "model = VGG16Cifar10(\"https://api.wuhanstudio.uk\" + \"/vgg16_cifar10\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "airplane       0.00001\n",
      "automobile     0.00001\n",
      "bird           0.00003\n",
      "cat            0.00002\n",
      "deer           0.00003\n",
      "dog            0.99964\n",
      "frog           0.00001\n",
      "horse          0.00024\n",
      "ship           0.00000\n",
      "truck          0.00001\n",
      "\n",
      "Prediction 5 dog\n"
     ]
    }
   ],
   "source": [
    "# Get Preditction\n",
    "y_pred = model.predict(np.array([x]))[0]\n",
    "\n",
    "# Print result\n",
    "model.print(y_pred)\n",
    "print()\n",
    "print('Prediction', np.argmax(y_pred), model.get_class_name(np.argmax(y_pred)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: Apply the SimpleBA Attack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Distributed SimBA:  50%|██████████████████████████████████████████████████████                                                      | 10/20 [00:38<00:38,  3.86s/it, origin prob=0.284, l2 norm=1.31]\n"
     ]
    }
   ],
   "source": [
    "simba = SimBA(model)\n",
    "x_adv = simba.attack(x, epsilon=0.1, max_it=1000, distributed=True, batch=50, max_workers=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x24bae4f5488>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAeWklEQVR4nO2dfYxc53Xen3PvfOw3ucsv0yQlyjQVfVgSJa1UuZYcR2kM1TEgGw0MGa2rP4QoCOKiLlIUggPEKtAWTlHb8B+FC7oSIqeuP2rZtdC6bRQ1ga04okg5FCWLsk1RlEiKXxI/dnd2d2bu3NM/ZhRQ6vu8uyR3Z2W/zw8gOPuefe898849c2ffZ8455u4QQvzqk620A0KI/qBgFyIRFOxCJIKCXYhEULALkQgKdiESoXIpk83sLgBfBpAD+M/u/vnY7w8P1n31qiF2tMjMsDw4UKvSGaPDw9RWFk1qK5rcZpaHxyvcD8sjS+wdasordT4vC/sBAJglU0b4HMv4e/58q01th197nc9rhueZ8XPlkbVaNcT9H6oW1FYSZdkil1vsSmTX4kLkGT8qs3Wcr8fUfPjamZqewezcfPCAFx3s1r3y/yOA3wJwBMBuM3vM3V9gc1avGsLv/5M7yfEiF2NZBse3X7aRzrnz/ZPUNnvyZWo7dfAAteUDY8Hx2jj3o756LbWhmKGm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vLH593zT4N4ACA/wagfiHH1TfohEiE1DfohEgGBbsQiaBgFyIRFOxCJIKCXYhEULALkQgKdiESQcEuRCL8P/Uz70P6AD2LAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "imshow(np.asarray(x_adv))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "airplane       0.00005\n",
      "automobile     0.00003\n",
      "bird           0.00036\n",
      "cat            0.00115\n",
      "deer           0.00060\n",
      "dog            0.28446\n",
      "frog           0.00003\n",
      "horse          0.71330\n",
      "ship           0.00001\n",
      "truck          0.00002\n",
      "\n",
      "Prediction 7 horse\n"
     ]
    }
   ],
   "source": [
    "# Get predictions after attack\n",
    "y_pred = model.predict(np.array([x_adv]))[0]\n",
    "\n",
    "# Print result\n",
    "model.print(y_pred)\n",
    "print()\n",
    "print('Prediction', np.argmax(y_pred), model.get_class_name(np.argmax(y_pred)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
